package demo.huodongbaoming.controller;

import demo.huodongbaoming.dto.ActivityDTO;
import demo.huodongbaoming.dto.ResponseResult;
import demo.huodongbaoming.dto.UserDTO;
import demo.huodongbaoming.service.ActivityService;
import demo.huodongbaoming.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.persistence.EntityNotFoundException;
import java.util.List;

@RestController
@RequestMapping("/api/admin")
public class AdminController {

    @Autowired
    private UserService userService;

    @Autowired
    private ActivityService activityService;

    @GetMapping("/users")
    public ResponseResult<List<UserDTO>> getAllUsers() {
        // 这里需要添加管理员权限检查
        return ResponseResult.success(userService.getAllUsers());
    }

    @GetMapping("/activities")
    public ResponseResult<List<ActivityDTO>> getAllActivities() {
        // 这里需要添加管理员权限检查
        return ResponseResult.success(activityService.getAllActivities());
    }

    @PutMapping("/activities/{id}/status")
    public ResponseResult<ActivityDTO> updateActivityStatus(@PathVariable Long id, @RequestParam boolean isActive) {
        // 这里需要添加管理员权限检查
        try {
            ActivityDTO activityDTO = activityService.updateActivityStatus(id, isActive);
            return ResponseResult.success("活动状态更新成功", activityDTO);
        } catch (EntityNotFoundException e) {
            return ResponseResult.fail(404, e.getMessage());
        }
    }

    @DeleteMapping("/users/{id}")
    public ResponseResult<Void> deleteUser(@PathVariable Long id) {
        // 这里需要添加管理员权限检查
        try {
            userService.deleteUser(id);
            return ResponseResult.success("用户删除成功", null);
        } catch (EntityNotFoundException e) {
            return ResponseResult.fail(404, e.getMessage());
        }
    }
} 